//
//  doubleFileTableCell.m
//  doubleImage
//
//  Created by heyong on 16/9/26.
//  Copyright © 2016年 heyong. All rights reserved.
//

#define leftSpacing 10.
#define TITLE @"附件信息"

#import "doubleFileTableCell.h"
#import "Masonry.h"

@implementation doubleFileTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        [self createView];
    }
    return self;
}

-(void)createView{
    WEAKSELF
    UILabel *titleLab=[[UILabel alloc] initWithFrame:CGRectMake(leftSpacing, 0,DEF_SCREEN_WIDTH-30 , 30)];
    titleLab.text=TITLE;
    titleLab.textColor=[TTTheme defaultManger].selectColor;
    titleLab.font=[UIFont systemFontOfSize:16*BIZ];
    [self.contentView addSubview:titleLab];
    //横分割线
    UIView *view_1=[[UIView alloc]init];
    [self.contentView addSubview:view_1];
    [view_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(leftSpacing);
        make.right.mas_offset(-leftSpacing);
        make.height.mas_offset(1);
        make.top.mas_equalTo(titleLab.mas_bottom).mas_offset(15);
    }];
    view_1.backgroundColor=[UIColor colorWithRed:0.86 green:0.87 blue:0.87 alpha:1.00];
    
    //整改前文字
    UILabel *leftLab=[[UILabel alloc]init];
    leftLab.backgroundColor=[UIColor whiteColor];
    leftLab.textColor=UIColorFromRGB(0x797979);
    leftLab.font=[UIFont systemFontOfSize:15.];

    leftLab.text=@"整改前附件";
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:leftLab.text];
    // 改变特定范围颜色大小要用的
    NSRange r = NSMakeRange(2, 1);
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.00 green:0.59 blue:0.54 alpha:1.00] range:r];
    [leftLab setAttributedText:attributedString];

    leftLab.textAlignment=1;
    [self.contentView addSubview:leftLab];
    [leftLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(view_1.mas_left).offset(40);
        make.right.mas_equalTo(view_1.mas_centerX).offset(-40);
        make.top.mas_equalTo(view_1.mas_top).offset(-15);
        make.height.mas_offset(30);
    }];

    rightLab=[[UILabel alloc]init];
    rightLab.font=[UIFont systemFontOfSize:15.];
    rightLab.textColor=UIColorFromRGB(0x797979);
    rightLab.backgroundColor=[UIColor whiteColor];
    rightLab.text=@"整改后附件";
    rightLab.textAlignment=1;
    [self.contentView addSubview:rightLab];
    [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(view_1.mas_centerX).offset(40);
        make.right.mas_equalTo(view_1.mas_right).offset(-40);
        make.top.mas_equalTo(view_1.mas_top).offset(-15);
        make.height.mas_offset(30);
    }];
    NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc] initWithString:rightLab.text];
    // 改变特定范围颜色大小要用的
    NSRange r2 = NSMakeRange(2, 1);
    [attributedString2 addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.00 green:0.59 blue:0.54 alpha:1.00] range:r2];
    [rightLab setAttributedText:attributedString2];
    
    //竖线
    UIView *view_2=[[UIView alloc]init];
    [self.contentView addSubview:view_2];
    [view_2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(view_1.mas_centerX);
        make.top.mas_equalTo(view_1.mas_bottom).mas_offset(0);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        make.width.offset(1);
    }];
    view_2.backgroundColor=[UIColor colorWithRed:0.86 green:0.87 blue:0.87 alpha:1.00];
    
}


+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"doubleImage";
    doubleFileTableCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[doubleFileTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (void)setLeftImageArr:(NSArray *)leftArr andRightImageArr:(NSArray *)rightArr{
    WEAKSELF
    //整改前附件
    for (int i=0; i<leftArr.count; i++) {
        UIImageView *imageV=[[UIImageView alloc]init];
        imageV.frame=CGRectMake(leftSpacing, 65+105*i, DEF_SCREEN_WIDTH/2-2*leftSpacing, 100);
        imageV.image=[UIImage imageWithContentsOfFile:leftArr[i]];
        imageV.layer.cornerRadius=8.;
        imageV.layer.masksToBounds=YES;
        [weakSelf.contentView addSubview:imageV];
        imageV.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImage:)];
        [imageV addGestureRecognizer:tap];

    }
    //整改后附件
    for (int i=0; i<rightArr.count; i++) {
        UIImageView *imageV=[[UIImageView alloc]init];
        imageV.frame=CGRectMake(DEF_SCREEN_WIDTH/2+leftSpacing, 65+105*i, DEF_SCREEN_WIDTH/2-2*leftSpacing, 100);
        imageV.image=[UIImage imageWithContentsOfFile:rightArr[i]];
        imageV.layer.cornerRadius=8.;
        imageV.layer.masksToBounds=YES;
        [weakSelf.contentView addSubview:imageV];
        imageV.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImage:)];
        [imageV addGestureRecognizer:tap];
    }
}

- (void)clickImage:(UITapGestureRecognizer *)gesture{
    [LSTarBrowser showImage:(UIImageView *)gesture.view];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
